package hust.ning;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.json.JSONException;
import org.json.JSONObject;

@SuppressWarnings("serial")
public class LogoutServlet extends HttpServlet {
	public void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws IOException {
		resp.setContentType("text/plain;charset=UTF-8");
		resp.setHeader("Cache-Control","no-cache");
		String uid = req.getParameter("sessionID");
		ChatApp.getInstance().logout(uid);
		JSONObject obj = new JSONObject();
		try {
			obj.put("state", "disconnected");
		} catch (JSONException e) {
			e.printStackTrace();
		}
		resp.getWriter().print(obj.toString());
	}
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		doGet(req, resp);
	}
}
